added Feb 2001 SDK
[windows-sources.git] / shared source / wpf / src / host / shimimpl / markupversion.cxx
blobf36fc09f1fb28ad5836a7fd1d84339a92cc80cf0
1 //------------------------------------------------------------------------
2 //
3 // Copyright (c) Microsoft Corporation. All rights reserved.
4 //
5 // Description:
6 // Implements the interface to the application manifest
7 //
8 // History:
9 // 2005/05/09 - [....] Created
10 // 2007/09/20 [....] Ported Windows->DevDiv. See SourcesHistory.txt.
12 //------------------------------------------------------------------------
14 #include "PreCompiled.hxx"
15 #include "MarkupVersion.hxx"
16 #include "..\inc\registry.hxx"
19 #define COMPATURL L"http://schemas.openxmlformats.org/markup-compatibility/2006"
20 #define COMPATURL_LENGTH 63
22 #define IGNORABLE L"Ignorable"
23 #define IGNORABLE_LENGTH 9
25 #define MAX_PREFIX_LENGTH 128
27 CMarkupVersion::CMarkupVersion(__in LPCWSTR pswzLocalMarkupPath)
29 SetLocalMarkupPath(pswzLocalMarkupPath);
30 m_refCount = 0;
33 STDMETHODIMP CMarkupVersion::QueryInterface(const struct _GUID &riid,void ** ppvObject)
35 *ppvObject = NULL;
37 if (riid == IID_IUnknown)
39 *ppvObject = static_cast<ISAXContentHandler *>(this);
41 else if (riid == __uuidof(ISAXContentHandler))
43 *ppvObject = static_cast<ISAXContentHandler *>(this);
46 if (*ppvObject)
48 AddRef();
49 return S_OK;
51 else
53 return E_NOINTERFACE;
57 STDMETHODIMP_(DWORD) CMarkupVersion::AddRef()
59 return InterlockedIncrement(&m_refCount);
62 STDMETHODIMP_(DWORD) CMarkupVersion::Release()
64 InterlockedDecrement(&m_refCount);
65 if (m_refCount == 0)
67 delete this;
68 return 0;
70 else
72 return m_refCount;
76 IFACEMETHODIMP CMarkupVersion::startPrefixMapping(
77 __in const wchar_t* pwchPrefix,
78 __in int /*cchPrefix*/,
79 __in const wchar_t* pwchUri,
80 __in int /*cchUri*/)
82 HRESULT hr = S_OK;
84 // Accumulate and record the namespaces
86 // See if it is a namespace that we know.
87 CString* strVersion = NULL;
88 if (SUCCEEDED(m_mapNamespaceVersion.Find(pwchUri, &strVersion)))
90 CString *pUriString = CString::CreateOnHeap(pwchUri);
91 CK_ALLOC(pUriString);
92 CKHR(m_mapPrefixNamespace.Add(pwchPrefix, pUriString));
95 Cleanup:
96 return hr;
99 IFACEMETHODIMP CMarkupVersion::startElement(
100 __in_ecount(cchNamespaceUri) const wchar_t *pwchNamespaceUri,
101 __in int cchNamespaceUri,
102 __in_ecount(cchLocalName) const wchar_t *pwchLocalName,
103 __in int cchLocalName,
104 __in_ecount(cchQName) const wchar_t *pwchQName,
105 __in int cchQName,
106 __in ISAXAttributes *pAttributes)
108 HRESULT hr = S_OK;
110 const UINT BUFFER_LENGTH = 1024;
111 LPCWSTR pwzValue;
113 // This retrieves a space-delimited list of the ignorable prefices.
114 // If there is some error finding the attribute, or if it wasn't there, we don't care.
115 // Returning a failed HRESULT will stop the parsing. The namespaces have already been
116 // reported in startPrefixMapping.
117 int nLength = BUFFER_LENGTH;
118 CKHR(pAttributes->getValueFromName(COMPATURL, COMPATURL_LENGTH, IGNORABLE, IGNORABLE_LENGTH, &pwzValue, &nLength));
120 WCHAR wzPrefix[MAX_PREFIX_LENGTH];
121 LPCWSTR pStart = pwzValue;
122 while (*pStart)
124 // Remove any leading spaces
125 while (*pStart && *pStart == L' ')
127 ++pStart;
130 // Get the prefix from the space-delimited list
131 __bound UINT nIndex = 0;
132 while (*pStart && *pStart != L' ' && nIndex < MAX_PREFIX_LENGTH - 1)
134 wzPrefix[nIndex++] = *(pStart++);
136 wzPrefix[nIndex] = 0;
138 if (*wzPrefix)
140 CString* pStrNamespace = NULL;
141 if (SUCCEEDED(m_mapPrefixNamespace.Find(wzPrefix, &pStrNamespace)))
143 // This is a namespace we know about
144 CString* pStrVersion = NULL;
145 if (SUCCEEDED(m_mapNamespaceVersion.Find(pStrNamespace->GetValue(), &pStrVersion)))
147 CKHR(m_mapIgnorableNamespaceVersion.Add(pStrNamespace->GetValue(), pStrVersion));
153 CKHR(E_FAIL); // to stop the parsing
155 Cleanup:
156 return hr;
159 HRESULT CMarkupVersion::Read()
161 HRESULT hr = S_OK;
162 ISAXXMLReader* pReader = NULL;
164 EventWriteWpfHostUm_ParsingMarkupVersionStart();
166 CKHR(GetStringMapFromRegistry(HKEY_LOCAL_MACHINE, RegKey_WPF_Namespaces, m_mapNamespaceVersion));
168 if (m_mapNamespaceVersion.GetCount() > 0)
170 CKHR(CoCreateInstance(__uuidof(SAXXMLReader), NULL, CLSCTX_INPROC_SERVER, __uuidof(ISAXXMLReader), (void**)&pReader));
171 CKHR(pReader->putContentHandler(this));
172 hr = pReader->parseURL(GetLocalMarkupPath());
174 // If we stopped the parse because we found the version, hr will be E_FAIL and
175 // the version will be set in the manifest.
176 if (hr == E_FAIL)
178 hr = S_OK;
182 EventWriteWpfHostUm_ParsingMarkupVersionEnd();
184 Cleanup:
185 SAFERELEASE_POINTER(pReader);
187 return hr;